set more off
cd ""
cap log close 

import delimited "replication_data_thuerk.csv", clear


******* models full data set 1 to 6
**model 1 (agenda control)
fracreg logit gov_control i.status coalition minority_exp enp median short_term polarization support_share, vce(cluster country_id) 
estimates store m1

**model 2 (agenda control)
fracreg logit gov_control i.status coalition minority_exp support_share, vce(cluster country_id)
estimates store m2

**model 3 (agenda control)
fracreg logit gov_control i.status coalition minority_exp support_share committee, vce(cluster country_id)
estimates store m3

**model 4 (bill success)
fracreg logit gov_success i.status coalition minority_exp enp median short_term polarization, vce(cluster country_id)
estimates store m4

**model 5 (bill success)
fracreg logit gov_success i.status minority_exp short_term, vce(cluster country_id)
estimates store m5

**model 6 (bill success)
fracreg logit gov_success i.status minority_exp short_term committee, vce(cluster country_id)
estimates store m6


**** Figure 3
fracreg logit gov_control i.status coalition minority_exp support_share, vce(cluster country_id)
margins, dydx(*) 
estimates store Agenda_control
fracreg logit gov_success i.status minority_exp short_term, vce(cluster country_id)
margins, dydx(*) 
estimates store Bill_success

coefplot Agenda_control Bill_success, vert levels(95 90) ///
yline(0) xlabel(1 "Minority no support" 2 "Minority with support" , grid noticks) xscale(lstyle(none)) ylabel(, nogrid) ytitle("Average marginal effects") legend(rows(1) pos(6)) drop(minority_exp support_share short_term coalition _cons) saving(coef2, replace)

**** Figure 4
fracreg logit gov_control i.status coalition minority_exp support_share, vce(cluster country_id)
margins, at(status=0 status=1 status=2) atmeans
marginsplot, recast(scatter) recastci(rspike) saving(margins1, replace)

fracreg logit gov_success i.status minority_exp short_term, vce(cluster country_id)
margins, at(status=0 status=1 status=2) atmeans
marginsplot, recast(scatter) recastci(rspike) saving(margins2, replace)
*combine
graph combine margins1.gph margins2.gph



******* models minority cabinets only 7 to 14
** model 7 (agenda control)
fracreg logit gov_control i.status2 coalition minority_exp enp median short_term seatshare polarization support_share, vce(cluster country_id) 
estimates store p1

**model 8 (agenda control)
fracreg logit gov_control i.status2 coalition minority_exp short_term support_share, vce(cluster country_id) 
estimates store p2

**model 9 (agenda control - both types of support)
fracreg logit gov_control majority_support coalition minority_exp short_term support_share, vce(cluster country_id) 
estimates store p3

**model 10 (agenda control)
fracreg logit gov_control i.status2 coalition minority_exp short_term committee support_share, vce(cluster country_id) 
estimates store p4

**model 11 (bill success)
fracreg logit gov_success i.status2 coalition minority_exp enp median short_term seatshare polarization, vce(cluster country_id) 
estimates store p5

**model 12 (bill success)
fracreg logit gov_success i.status2 minority_exp short_term, vce(cluster country_id) 
estimates store p6

**model 13 (bill success)
fracreg logit gov_success majority_support  minority_exp short_term committee, vce(cluster country_id) 
estimates store p7

**model 14 (bill success)
fracreg logit gov_success i.status2 minority_exp short_term committee, vce(cluster country_id) 
estimates store p8


**** Figure 5
quietly fracreg logit gov_control majority_support coalition minority_exp short_term support_share, vce(cluster country_id)
quietly margins, dydx(majority_support) 
est store model9

quietly fracreg logit gov_success majority_support minority_exp short_term committee, vce(cluster country_id)
quietly margins, dydx(majority_support) 
est store model14

quietly fracreg logit gov_control i.status2 coalition minority_exp short_term support_share, vce(cluster country_id)
quietly margins, dydx(status2) 
est store model8

quietly fracreg logit gov_success i.status2 minority_exp short_term committee, vce(cluster country_id)
quietly margins, dydx(status2) 
est store model13

coefplot model9 model14 model8 model13, vert levels(95 90) ///
yline(0) xlabel(1 "Both support types" 2 "Announced support" 3 "Written support" , grid noticks) xscale(lstyle(none)) ylabel(, nogrid) ytitle("Average marginal effects") legend(rows(1) pos(6)) drop(coalition minority_exp short_term support_share polarization committee _cons) saving(coef3, replace)


***** interaction effect models 
fracreg logit gov_control i.formal_majority##c.minority_exp coalition short_term support_share enp_seats, vce(cluster country_id) 
estimates store ia1

fracreg logit gov_control i.formal_majority##c.minority_exp coalition short_term support_share enp_seats committee, vce(cluster country_id) 
estimates store ia2

fracreg logit gov_control i.majority_support##c.minority_exp coalition short_term support_share enp_seats, vce(cluster country_id) 
estimates store ia3

fracreg logit gov_success i.formal_majority##c.minority_exp coalition short_term enp_seats, vce(cluster country_id)
estimates store ia4 

fracreg logit gov_success i.formal_majority##c.minority_exp coalition short_term committee, vce(cluster country_id) 
estimates store ia5

fracreg logit gov_success i.majority_support##c.minority_exp coalition short_term committee, vce(cluster country_id) 
estimates store ia6

****** Figure 6
quietly fracreg logit gov_control i.formal_majority##c.minority_exp coalition short_term support_share enp_seats
quietly margins formal_majority,at(minority_exp=(0(0.1)1))
marginsplot, xdimension(at(minority_exp)) recast(line) recastci(rline) legend(pos(6) ring(0) col(1)) ///
addplot(hist minority_exp, yaxis(2) yscale(alt axis(2)) percent fcolor(none) lcolor(black)) saving(ia1, replace)

quietly fracreg logit gov_success i.formal_majority##c.minority_exp coalition short_term committee
quietly margins formal_majo,at(minority_exp=(0(0.1)1))
marginsplot, xdimension(at(minority_exp)) recast(line) recastci(rline) legend(pos(5) ring(0) col(1)) ///
addplot(hist minority_exp, yaxis(2) yscale(alt axis(2)) percent fcolor(none) lcolor(black)) saving(ia2, replace)

graph combine ia1.gph ia2.gph




****************** R O B U S T N E S S ** C H E C K S ************************
**model 21 (agenda control)
reg gov_control i.status coalition minority_exp enp median short_term polarization support_share, vce(cluster country_id) 
estimates store ols1

**model 22 (agenda control)
reg gov_control i.status coalition minority_exp support_share, vce(cluster country_id)
estimates store ols2

**model 23 (bill success)
reg gov_success i.status minority_exp short_term, vce(cluster country_id)
estimates store ols3

**model 24 (bill success)
reg gov_success i.status minority_exp short_term committee, vce(cluster country_id)
estimates store ols4

**model 25 (agenda control)
reg gov_control i.status2 coalition minority_exp short_term support_share, vce(cluster country_id) 
estimates store ols5

**model 26 (agenda control)
reg gov_control majority_support coalition minority_exp short_term support_share, vce(cluster country_id) 
estimates store ols6

**model 27 (bill success)
reg gov_success majority_support  minority_exp short_term committee, vce(cluster country_id) 
estimates store ols7

**model 28 (bill success)
reg gov_success i.status2 minority_exp short_term committee, vce(cluster country_id) 
estimates store ols8


**** regional fixed effects ****
xtset re_gion

***Full dataset
xtreg gov_control i.status minority_exp coalition support_share, fe 
estimates store fe1
xtreg gov_success i.status minority_exp short_term committee, fe
estimates store fe2

***Minority only
xtreg gov_control i.status2 coalition minority_exp support_share, fe 
estimates store fe3
xtreg gov_success i.status2 minority_exp short_term committee, fe
estimates store fe4


***** reduced sample -> drop countries for which there are not observations for each status value
drop if country_id== 1
drop if country_id== 2
drop if country_id== 3
drop if country_id== 7
drop if country_id== 9
drop if country_id== 12
drop if country_id== 13
drop if country_id== 21

**model 33
fracreg logit gov_control i.status coalition minority_exp enp median short_term polarization support_share, vce(cluster country_id) 
estimates store sub1

**model 34
fracreg logit gov_control i.status coalition minority_exp support_share, vce(cluster country_id)
estimates store sub2

**model 35
fracreg logit gov_success i.status coalition minority_exp enp median short_term polarization, vce(cluster country_id)
estimates store sub3

**model 36
fracreg logit gov_success i.status coalition minority_exp short_term committee, vce(cluster country_id)
estimates store sub4
